package com.tencreat.mall.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencreat.common.annotation.Log;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.common.core.domain.AjaxResult;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.common.enums.BusinessType;
import com.tencreat.common.utils.poi.ExcelUtil;
import com.tencreat.domain.mall.MallGoodsHelpCutUser;
import com.tencreat.domain.mall.dto.MallGoodsHelpCutUserDTO;
import com.tencreat.service.mall.IMallGoodsHelpCutUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 帮砍记录Controller
 *
 * @author wangkai
 * @date 2021-11-04
 */
@Api(tags={"6-帮砍记录"})
//@RestController
@RequestMapping("/api/helpCutUser")
public class MallGoodsHelpCutUserController extends BaseController {
    //@Autowired
    private IMallGoodsHelpCutUserService mallGoodsHelpCutUserService;

    /**
     * 查询帮砍记录列表
     */
    @ApiOperation(value="查询帮砍记录列表")
    @PreAuthorize("@ss.hasPermi('system:user:list')")
    @PostMapping("/list")
    public HttpResult<IPage<MallGoodsHelpCutUser>> list(@RequestBody MallGoodsHelpCutUserDTO mallGoodsHelpCutUserDTO) {
        MallGoodsHelpCutUser mallGoodsHelpCutUser = new MallGoodsHelpCutUser();
        BeanUtils.copyProperties(mallGoodsHelpCutUserDTO,mallGoodsHelpCutUser);
        QueryWrapper<MallGoodsHelpCutUser> wrapper = Wrappers.query(mallGoodsHelpCutUser);
        Page<MallGoodsHelpCutUser> page =  new Page<>(mallGoodsHelpCutUser.getPageNum(), mallGoodsHelpCutUser.getPageSize());
        return HttpResult.ok(mallGoodsHelpCutUserService.page(page, wrapper));
    }

    /**
     * 导出帮砍记录列表
     */
    @ApiOperation(value="导出帮砍记录列表")
    @PreAuthorize("@ss.hasPermi('system:user:export')")
    @Log(title = "帮砍记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(MallGoodsHelpCutUser mallGoodsHelpCutUser) {
        List<MallGoodsHelpCutUser> list = mallGoodsHelpCutUserService.selectMallGoodsHelpCutUserList(mallGoodsHelpCutUser);
        ExcelUtil<MallGoodsHelpCutUser> util = new ExcelUtil<MallGoodsHelpCutUser>(MallGoodsHelpCutUser.class);
        return util.exportExcel(list, "user");
    }

    /**
     * 获取帮砍记录详细信息
     */
    @ApiOperation(value="获取帮砍记录详细信息")
    @PreAuthorize("@ss.hasPermi('system:user:query')")
    @PostMapping(value = "/getInfo")
    public HttpResult<MallGoodsHelpCutUser> getInfo(@RequestBody   ReqIdParam id) {
        return HttpResult.ok(mallGoodsHelpCutUserService.selectMallGoodsHelpCutUserById(id));
    }

    /**
     * 新增帮砍记录
     */
    @ApiOperation(value="新增帮砍记录")
    @PreAuthorize("@ss.hasPermi('system:user:add')")
    @Log(title = "帮砍记录", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public HttpResult<Boolean> add(@RequestBody  MallGoodsHelpCutUserDTO mallGoodsHelpCutUserDTO) {
        return to(mallGoodsHelpCutUserService.insertMallGoodsHelpCutUser(mallGoodsHelpCutUserDTO));
    }

    /**
     * 修改帮砍记录
     */
    @ApiOperation(value="修改帮砍记录")
    @PreAuthorize("@ss.hasPermi('system:user:edit')")
    @Log(title = "帮砍记录", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public HttpResult<Boolean> edit(@RequestBody  MallGoodsHelpCutUserDTO mallGoodsHelpCutUserDTO) {
        return to(mallGoodsHelpCutUserService.updateMallGoodsHelpCutUser(mallGoodsHelpCutUserDTO));
    }

    /**
     * 删除帮砍记录
     */
    @ApiOperation(value="删除帮砍记录")
    @PreAuthorize("@ss.hasPermi('system:user:remove')")
    @Log(title = "帮砍记录", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
    public HttpResult<Boolean> remove(@RequestBody  ReqIdsParam ids) {
        return to(mallGoodsHelpCutUserService.deleteMallGoodsHelpCutUserByIds(ids));
    }
}
